package com.wangdao.wechatmall.service.wx;

import com.wangdao.wechatmall.bean.bo.wx.WXFeedbackBO;
import com.wangdao.wechatmall.bean.pojo.Feedback;
import com.wangdao.wechatmall.mapper.FeedbackMapper;
import com.wangdao.wechatmall.mapper.UserMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * WXFeedbackServiceImpl
 * created by feng on 7/12/21
 */
@Service
public class WXFeedbackServiceImpl implements WXFeedbackService {

    @Autowired
    FeedbackMapper feedbackMapper;

    @Autowired
    UserMapper userMapper;


    @Override
    public Integer submit(WXFeedbackBO wxFeedbackBO) {

        Feedback feedback = new Feedback();
        feedback.setContent(wxFeedbackBO.getContent());
        feedback.setFeedType(wxFeedbackBO.getFeedType());
        feedback.setDeleted(false);
        feedback.setHasPicture(wxFeedbackBO.getHasPicture());
        feedback.setMobile(wxFeedbackBO.getMobile());
        feedback.setPicUrls(wxFeedbackBO.getPicUrls());
        feedback.setStatus(0);

        Date date = new Date();

        feedback.setUpdateTime(date);
        feedback.setAddTime(date);

        String userName = (String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        int userId = userMapper.queryId(userName);

        feedback.setUserId(userId);
        feedback.setUsername(userName);

        int affectedRow = feedbackMapper.insert(feedback);

        return affectedRow;
    }
}